﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace calculator
{
    [TestFixture]
    class BoolOperationTester
    {
        
        [Test]
        public void testForValidOperations()
        {
            try//This tests the weather the opeartion is valid
            {
                PerformOperation boolTester = new PerformOperation();//We are checking if "LAND" is an invalid operation, i.e. the class should throw an exception.
                boolTester.resultOfOperation(true, false, "LAND");
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                //The test is a success
            }
        }

        [Test]
        public void testORoperation()
        {
            PerformOperation boolTest = new PerformOperation();
            Assert.IsTrue(boolTest.resultOfOperation(false, true, "OR"));
            Assert.IsTrue(boolTest.resultOfOperation(true, false, "OR"));
            Assert.IsTrue(boolTest.resultOfOperation(true, true, "OR"));
            Assert.IsFalse(boolTest.resultOfOperation(false, false, "OR"));
        }

        [Test]
        public void testNOToperation()
        {
            PerformOperation boolTest = new PerformOperation();
            Assert.IsTrue(boolTest.resultOfOperation(false, "NOT"));
            Assert.IsFalse(boolTest.resultOfOperation(true, "NOT"));

            try
            {
                boolTest.resultOfOperation(false, "WAFFLES");
            }
            catch (ArgumentException)
            {
                //Successful test
            }
        }

        [Test]
        public void testANDoperation()
        {
            PerformOperation boolTest = new PerformOperation();
            Assert.IsTrue(boolTest.resultOfOperation(true, true, "AND"));
            Assert.IsFalse(boolTest.resultOfOperation(false, true, "AND"));
            Assert.IsFalse(boolTest.resultOfOperation(true, false, "AND"));
            Assert.IsFalse(boolTest.resultOfOperation(false, false, "AND"));
        }

        [Test]
        public void testXORoperation()
        {
            PerformOperation boolTest = new PerformOperation();
            Assert.IsTrue(boolTest.resultOfOperation(true, false, "XOR"));
            Assert.IsTrue(boolTest.resultOfOperation(false, true, "XOR"));
            Assert.IsFalse(boolTest.resultOfOperation(true, true, "XOR"));
            Assert.IsFalse(boolTest.resultOfOperation(false, false, "XOR"));
        }

        [Test]
        public void testNANDoperation()
        {
            PerformOperation boolTest = new PerformOperation();
            Assert.IsTrue(boolTest.resultOfOperation(false, false, "NAND"));
            Assert.IsTrue(boolTest.resultOfOperation(true, false, "NAND"));
            Assert.IsTrue(boolTest.resultOfOperation(false, true, "NAND"));
            Assert.IsFalse(boolTest.resultOfOperation(true, true, "NAND"));
        }

        [Test]
        public void testNORoperation()
        {
            PerformOperation boolTest = new PerformOperation();
            Assert.IsTrue(boolTest.resultOfOperation(false, false, "NOR"));
            Assert.IsFalse(boolTest.resultOfOperation(true, false, "NOR"));
            Assert.IsFalse(boolTest.resultOfOperation(false, true, "NOR"));
            Assert.IsFalse(boolTest.resultOfOperation(true, true, "NOR"));
        }

        [Test]
        public void testIFFoperation()
        {
            PerformOperation boolTest = new PerformOperation();
            Assert.IsTrue(boolTest.resultOfOperation(false, false, "IFF"));
            Assert.IsFalse(boolTest.resultOfOperation(true, false, "IFF"));
            Assert.IsFalse(boolTest.resultOfOperation(false, true, "IFF"));
            Assert.IsTrue(boolTest.resultOfOperation(true, true, "IFF"));
        }

        [Test]
        public void testIFNoperation()
        {
            PerformOperation boolTest = new PerformOperation();
            Assert.IsTrue(boolTest.resultOfOperation(false, false, "IFN"));
            Assert.IsFalse(boolTest.resultOfOperation(true, false, "IFN"));
            Assert.IsTrue(boolTest.resultOfOperation(false, true, "IFN"));
            Assert.IsTrue(boolTest.resultOfOperation(true, true, "IFN"));
        }

        [Test]
        public void testXNORoperation()
        {
            PerformOperation boolTest = new PerformOperation();
            Assert.IsTrue(boolTest.resultOfOperation(false, false, "XNOR"));
            Assert.IsFalse(boolTest.resultOfOperation(true, false, "XNOR"));
            Assert.IsFalse(boolTest.resultOfOperation(false, true, "XNOR"));
            Assert.IsTrue(boolTest.resultOfOperation(true, true, "XNOR"));
        }

        [Test]
        public void testBoolArray()
        {
            bool[] firstTestArray = new bool[] { false, false, true, true };
            bool[] secondTestArray = new bool[] { false, true, false, true };
            PerformOperation boolTest = new PerformOperation();
            Assert.AreEqual(new bool[] { false, false, false, true }, boolTest.resultOfOperation(firstTestArray, secondTestArray, "AND"));
            Assert.AreEqual(new bool[] { true, true, false, false }, boolTest.resultOfOperation(firstTestArray, "NOT"));
            
        }
 
    }
}
